<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/headeradmin.php");
?>

<section>

<?php

// A check if the id is still a numeric character and hasn't been changed manually
if (!is_numeric($_GET['id'])) { 
    header("Location: ".$cfg['basepath']."controller/gebouw/gebouw.php");
}

// Retrieves all the data of the selected building from the database
$getBuilding = GetBuildingById($_GET['id']);
while($buildingRow = mysql_fetch_array($getBuilding))
{
    echo "<hgroup><h1>".$buildingRow['@street']." ".$buildingRow['@number']."</h1></hgroup>";
    echo "<br>";

    // Retrieves the city of the selected building from the database
    $getCity = GetCityById($buildingRow['@cityid']);
    while($cityRow = mysql_fetch_array($getCity))
    {
        echo "<span style=\"font-weight: bold\">Postcode:</span> ".$cityRow['@zip']."";
        echo "<br>";
        echo "<span style=\"font-weight: bold\">Gemeente:</span> ".$cityRow['@city']."";
        echo "<br>";
    }
    
    $yearofconstruction = date("Y",strtotime($buildingRow['@yearofconstruction']));
    echo "<span style=\"font-weight: bold\">Bouwjaar:</span> ".$yearofconstruction."";
    echo "<br>";
    
    // Retrieves the building-type of the selected building from the database
    $getBuildingType = GetBuildingTypeById($buildingRow['@buildingtypeid']);
    while($buildingtypeRow = mysql_fetch_array($getBuildingType))
    {
        echo "<span style=\"font-weight: bold\">Type:</span> ".$buildingtypeRow['@name']."";
        echo "<br>";
    }
    
    // Retrieves the person who lives in the selected building from the database
    $getPatient = GetPatientByBuildingId($_GET['id']);
    while ($patientRow = mysql_fetch_array($getPatient))
    {
        echo "<span style=\"font-weight: bold\">Bewoner:</span> ".$patientRow['@firstname']." ".$patientRow['@lastname']." (<a href=\" ".$cfg['basepath']."controller/patient/patientdetail.php?id=".$patientRow['@id']."\" >Bekijk bewoner-details</a>)";
        echo "<br>";
    }
    
    // Retrieves the details of the selected building from the database
    $BuildingSpecs = GetAllBuildingSpecs();
    while($buildingspecRow = mysql_fetch_array($BuildingSpecs))
    {
        $BuildingDetail = GetBuildingDetail($_GET['id'], $buildingspecRow['Id']);
        while($buildingdetailRow = mysql_fetch_array($BuildingDetail))
        {
            echo "<span style=\"font-weight: bold\">".$buildingspecRow['BuildingKey'].":</span> ".$buildingdetailRow['Value']."";
            echo "<br>";
        }
    } 
}
?>
    <br>
<input type="button" value="Terug" onclick="window.location='gebouw.php';" />
    
</section>

<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>